package com.wanxi.step07test.task;

import com.wanxi.step07test.mapper.SUserMapper;
import com.wanxi.step07test.model.SUser;
import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.core.AmqpTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@Slf4j
public class SendEmailTask {
    @Autowired
    private SUserMapper userMapper;

    @Autowired
    private AmqpTemplate amqpTemplate;

//    @Scheduled(cron = "0 37 17 * * ?") // 每天的17点37分触发任务
//    @Scheduled(fixedRate = 5000)

    public void sendEmail(){
        List<SUser> allEmail = userMapper.findAllEmail();
        amqpTemplate.convertAndSend("email.topic","email.online",allEmail);
        log.info("看这里的信息: {}","管理员的邮箱库已经发送到消息队列");
    }
}
